package com.q.tqb.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.q.tqb.R;
import com.q.tqb.model.NewHomeInfo;
import com.q.tqb.model.RedListData;

import java.util.List;

public class NewHomeAdapter extends BaseSectionQuickAdapter<NewHomeInfo, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param layoutResId      The layout resource id of each item.
     * @param sectionHeadResId The section head layout id for each item
     * @param data             A new list is created out of this one to avoid mutable list
     */
    public NewHomeAdapter(int layoutResId, int sectionHeadResId, List data) {
        super(layoutResId, sectionHeadResId, data);
    }


    @Override
    protected void convertHead(BaseViewHolder helper, NewHomeInfo item) {
        helper.setText(R.id.tv, item.getPacket_name());
    }

    @Override
    protected void convert(BaseViewHolder helper, NewHomeInfo item) {
        RedListData redListData = item.t;
        // 加载网络图片
        Glide.with(mContext)
                .load(redListData.getHeader())
                .crossFade()
                .error(R.drawable.ic_head)
                .placeholder(R.drawable.ic_head)
                .into((ImageView) helper.getView(R.id.iv_head));

        helper.setText(R.id.tv_name, redListData.getNickname());
        helper.setText(R.id.tv_money, "共" + redListData.getPacket_money() + "元");
        helper.setText(R.id.tv_amount, redListData.getGet_num() + "/" + redListData.getPacket_num() + "个");

        if (redListData.getIs_users_agent() == 1) {
            helper.getView(R.id.iv_vip).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.iv_vip).setVisibility(View.GONE);
        }

        if (TextUtils.isEmpty(redListData.getPacket_content())) {
            helper.setText(R.id.tv_content, redListData.getPacket_title());
        } else {
            helper.setText(R.id.tv_content, redListData.getPacket_content());
        }

        if (redListData.getGet_num() == redListData.getPacket_num()) {
            helper.getView(R.id.iv_red_finish).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.iv_red_finish).setVisibility(View.GONE);
        }
    }
}
